<link rel="stylesheet" type="text/css" href="assets/bootstrap-datepicker/css/datepicker.css" />
<section id="container">
  <!--main content start-->
  <section id="main-content">
    <section class="wrapper">
      <!--state overview end-->
      <div class="row">
        <div class="col-lg-12">
            <div class="alert alert-block alert-danger fade in">
                <button data-dismiss="alert" class="close close-sm" type="button">
                    <i class="icon-remove"></i>
                </button>
                <strong>友情提示：</strong><br />
                1、每月最后一个工作日需要相关人员完成用服人员、开发人员的成本确认，完成成本的设定。每月月末25号人事控制月底入职电子流，每月最后倒数第三个工作日相关人员完成用服人员归集并提交确认。每月最后倒数第二个工作日前相关人员完成开发人员归集和各部门确认，并提交确认。每月倒数第二个工作日相关人员完成成本设定；<br />
                2、 一旦用服人员或者研发人员的成本归集提交确认后，本月就不能再修改。系统自动把未分配人员设定为销管成本；<br />
                3、只有投入到客服的人员才可以填写客服工时；<br />
                4、核对本月人员改动时，只需查看各个成本分类下列表前部分中设定时间为本月的记录和历史无效记录中本月的改动即可（未分配的会自动处理）；
            </div>
            <section class="panel" id="stepCmt" style="display: none">
                <header class="panel-heading">
                    成员类型变更<span style="color: red;font-weight: bold">（人员成本若发生变化，请务必和相关部门确认之后再提交，一旦提交系统自动完成相关计算和归档，
                    无法回退处理！）</span>
                </header>
                <div class="panel-body">
                    <div class="form-group customerForm">
                        <label class="col-sm-2 control-label">变更说明</label>
                        <div class="col-sm-10">
                            <textarea class="form-control bg" id="stepComment" maxlength="120"
                                      onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');" placeholder="120字以内"></textarea>
                        </div>
                    </div>
                    <p class="default-buttons">
                        <a href="javascript:void(0);" class="button-back btn btn-info" onclick="cleanCmt()">取消</a>
                        <a href="javascript:void(0);" class="button-next  btn btn-info" onclick="addCmt()">提交</a>
                    </p>
                </div>
            </section>

          <section class="panel">
            <header class="panel-heading">
                人员归集
            </header>
            <div class="panel-body">
                <div class="row">
                    <div class="col-lg-3" style="width: 200px;">
                        <div class="input-group m-bot15">
                            <span class="input-group-addon" style="position: relative;z-index: 2;">类型</span>
                            <select class="form-control"
                                    style="position: relative;margin-left:-4px;text-indent:2px;width: 119px;"
                                    id="costType">
                                <option value="">全部</option>
                                <option value="KF-001">开发成本</option>
                                <option value="YF-001">用服成本</option>
                                <option value="OT-001">销售和管理</option>
                                <option value="N" selected>未分配员工</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-lg-3" style="margin-left: -16px;width: 200px;">
                        <div class="input-group m-bot15">
                            <span class="input-group-addon">姓名</span>
                            <input type="text" id="useNameN" onkeyup="cleaUser()" class="form-control">
                            <input type="hidden" value="" name="userIdN" id="userIdN"/>
                        </div>
                    </div>
                    <div class="col-lg-3" style="width: 200px;margin-left: -16px;">
                        <div class="input-group m-bot15">
                            <span class="input-group-addon">公司</span>
                            <select class="form-control"
                                    id="companyCodeN">
                                <option value="" selected>全部</option>
                                <!--<option value="HFKJ">浩方科技</option>-->
                                <!--<option value="HFXX">浩方信息</option>-->
                                <option value="STSBJ">赛特斯北京</option>
                                <option value="STSGD">赛特斯广东</option>
                                <!--<option value="STSJT">赛特斯集团</option>-->
                                <option value="STSNJ">赛特斯南京</option>
                                <option value="STSSH">赛特斯上海</option>
                                <!--<option value="SYB-DL">电力事业部</option>-->
                                <!--<option value="SYB-RX">融合运维事业部</option>-->
                            </select>
                        </div>
                    </div>
                    <div class="col-lg-3" style="width: 200px;margin-left: -16px;">
                        <div class="input-group m-bot15">
                            <span class="input-group-addon">部门</span>
                            <input type="text" id="deptCodeN" value="" class="form-control">
                            <!--<select class="form-control"-->
                                    <!--id="deptCodeN">-->
                                <!--<option value="" selected>全部</option>-->
                                <!--<option ng-repeat="x in depts" value="{{x.departmentCode}}">{{x.departmentName}}</option>-->
                            <!--</select>-->
                        </div>
                    </div>
                    <div class="col-lg-3" style="margin-left: -106px;" id="begindiv">
                        <div class="input-group m-bot15">
                            <span class="input-group-addon">开始日期</span>
                            <input type="text"  id="beginTime" autocomplete="off" value="" style="width: 100px;" class="form-control">
                        </div>
                    </div>
                    <div class="col-lg-3" style="margin-left: -93px;" id="enddiv">
                        <div class="input-group m-bot15">
                            <span class="input-group-addon">结束日期</span>
                            <input type="text" id="endTime" autocomplete="off" value="" style="width: 100px;"  class="form-control">
                        </div>
                    </div>
                    <div class="col-lg-3" style="width: 34%;margin-left: -11px;">
                        <button class="btn btn-info psearch" style="margin-bottom:15px;">搜索</button>
                        <button class="btn btn-info tjyf" style="margin-bottom:15px;">提交用服人员</button>
                        <button class="btn btn-info tjkf" style="margin-bottom:15px;">提交开发人员</button>
                    </div>
                </div>
              <div id="cuserContainer" class="dlshouwen-grid-container"></div>
              <div id="cuserToolContainer" class="dlshouwen-grid-toolbar-container"></div>

            </div>
          </section>
            <section class="panel" id="isShowBg">
                <header class="panel-heading">
                    成员类型变更<span style="color: red;font-weight: bold">（人员成本若发生变化，请务必和相关部门确认之后再提交，一旦提交系统自动完成相关计算和归档，
                    无法回退处理！）</span>
                </header>
                <div class="panel-body">
                    <div class="form-group customerForm">
                        <label class="col-sm-2 control-label">姓名</label>
                        <div class="col-sm-10">
                            <input type="text" value="{{userName}}" readonly class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group customerForm">
                        <label class="col-sm-2 control-label">公司</label>
                        <div class="col-sm-10">
                            <input type="text" value="{{company}}" readonly class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group customerForm">
                        <label class="col-sm-2 control-label">岗位</label>
                        <div class="col-sm-10">
                            <input type="text" value="{{positionName}}" readonly class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group customerForm isYf">
                        <label class="col-sm-2 control-label">上市部门*</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="sdeptCode">
                                <option value="1">5G</option>
                                <option value="2">云服务</option>
                                <option value="3">NFV</option>
                                <option value="4">融合</option>
                                <option value="4">客服及产品支持部</option>
                                <!--<option ng-repeat="xx in sdeptList" value="{{xx.departmentCode}}">{{xx.departmentName}}-->
                                <!--</option>-->
                            </select>
                        </div>
                    </div>
                    <div class="form-group customerForm isYf">
                        <label class="col-sm-2 control-label">选择项目*</label>
                        <div class="col-sm-10">
                            <input type="text" value="" autocomplete="off" id="proName" class="form-control"
                                   placeholder="项目名称" />
                            <input type="hidden" value="" id="proId" name="proId" />
                        </div>
                    </div>
                    <div class="form-group customerForm isYf">
                        <label class="col-sm-2 control-label">选择模块*</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="moduleId">
                                <option value="0">请选择</option>
                                <option ng-repeat="xx in moduleList" value="{{xx.moduleId}}">{{xx.moduleName}}
                                </option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group customerForm isYf">
                        <label class="col-sm-2 control-label">角色*</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="roleId">
                                    <option value="17YF" selected class="ng-binding ng-scope">软件技术工程师</option>
                                    <!--<option value="20YF" class="ng-binding ng-scope">测试工程师</option>-->
                                </option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group customerForm">
                        <label class="col-sm-2 control-label">变更说明</label>
                        <div class="col-sm-10">
                            <textarea class="form-control bg" id="comment" maxlength="120"
                                      onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');"></textarea>
                        </div>
                    </div>
                    <p class="default-buttons">
                        <a href="javascript:void(0);" class="button-back btn btn-info" onclick="cleanOkrs()">取消</a>
                        <a href="javascript:void(0);" class="button-next  btn btn-info" onclick="addOkrs()">提交</a>
                    </p>
                </div>
            </section>

        </div>
          <div class="col-lg-12">
              <section class="panel">
                  <header class="panel-heading">
                      离职人员记录（非销管类）
                  </header>
                  <div class="panel-body">
                      <!--历史记录-->
                      <div id="lzContainer" class="dlshouwen-grid-container"></div>
                      <div id="lzHistryToolContainer" class="dlshouwen-grid-toolbar-container"></div>
                  </div>
              </section>
          </div>
          <div class="col-lg-12">
              <section class="panel">
                  <header class="panel-heading">
                      待入职人员
                  </header>
                  <div class="panel-body">
                      <!--历史记录-->
                      <div id="rzContainer" class="dlshouwen-grid-container"></div>
                      <div id="rzHistryToolContainer" class="dlshouwen-grid-toolbar-container"></div>
                  </div>
              </section>
          </div>
          <section class="panel">
              <header class="panel-heading">
                  历史归档记录
              </header>
              <div class="panel-body">
                  <div class="row">
                      <div class="col-lg-3" style="position: relative;margin-left:-4px;width: 159px;">
                          <div class="input-group m-bot15">
                              <span class="input-group-addon" style="position: relative;z-index: 2;">年</span>
                              <select class="form-control" id="pyear">
                                  <option value="0">请选择</option>
                                  <option value="2019">2019</option>
                                  <option value="2020">2020</option>
                                  <option value="2021">2021</option>
                                  <option value="2022">2022</option>
                              </select>
                          </div>
                      </div>
                      <div class="col-lg-3" style="margin-left: -16px;width: 159px">
                          <div class="input-group m-bot15">
                              <span class="input-group-addon" style="position: relative;z-index: 2;">月</span>
                              <select class="form-control" id="pmonth">
                                  <option value="0">请选择</option>
                                  <option value="1">1</option>
                                  <option value="2">2</option>
                                  <option value="3">3</option>
                                  <option value="4">4</option>
                                  <option value="5">5</option>
                                  <option value="6">6</option>
                                  <option value="7">7</option>
                                  <option value="8">8</option>
                                  <option value="9">9</option>
                                  <option value="10">10</option>
                                  <option value="11">11</option>
                                  <option value="12">12</option>
                              </select>
                          </div>
                      </div>
                      <div class="col-lg-3" style="margin-left: -16px;width: 200px;">
                          <div class="input-group m-bot15">
                              <span class="input-group-addon">姓名</span>
                              <input type="text" id="useName" onkeyup="cleaUser2()" class="form-control">
                              <input type="hidden" value="" name="userId" id="userId"/>
                          </div>
                      </div>
                      <div class="col-lg-3" style="width: 200px;margin-left: -16px;">
                          <div class="input-group m-bot15">
                              <span class="input-group-addon">公司</span>
                              <select class="form-control"
                                      id="companyCode">
                                  <option value="" selected>全部</option>
                                  <!--<option value="HFKJ">浩方科技</option>-->
                                  <!--<option value="HFXX">浩方信息</option>-->
                                  <option value="STSBJ">赛特斯北京</option>
                                  <option value="STSGD">赛特斯广东</option>
                                  <!--<option value="STSJT">赛特斯集团</option>-->
                                  <option value="STSNJ">赛特斯南京</option>
                                  <option value="STSSH">赛特斯上海</option>
                                  <!--<option value="SYB-DL">电力事业部</option>-->
                                  <!--<option value="SYB-RX">融合运维事业部</option>-->
                              </select>
                          </div>
                      </div>
                      <div class="col-lg-3" style="margin-left: -16px;width: 165px">
                          <div class="input-group m-bot15">
                              <span class="input-group-addon">类型</span>
                              <select class="form-control" id="lsCostType">
                                  <option value="">全部</option>
                                  <option value="KF-001">开发成本</option>
                                  <option value="YF-001">用服成本</option>
                                  <option value="OT-001">销售和管理</option>
                                  <option value="N">未分配员工</option>
                              </select>
                          </div>
                      </div>
                      <div class="col-lg-3" style="width: 200px;margin-left: -16px;">
                          <div class="input-group m-bot15">
                              <span class="input-group-addon">部门</span>
                              <input type="text" id="deptCode" class="form-control">
                          </div>
                      </div>
                      <div class="col-lg-3" style="margin-left: -9px;width: 190px;">
                          <button class="btn btn-info searchhis" style="margin-bottom:15px;">搜索</button>
                          <button class="btn btn-info downLoad" style="margin-bottom:15px;">下载</button>
                      </div>
                  </div>
                  <div id="aContainer" class="dlshouwen-grid-container"></div>
                  <div id="aToolContainer" class="dlshouwen-grid-toolbar-container"></div>

              </div>
          </section>

          <div class="col-lg-12">
              <section class="panel">
                  <header class="panel-heading">
                      历史无效记录
                  </header>
                  <div class="panel-body">
                      <!--历史记录-->
                      <div id="cuserHistryContainer" class="dlshouwen-grid-container"></div>
                      <div id="cuserHistryToolContainer" class="dlshouwen-grid-toolbar-container"></div>
                  </div>
              </section>
          </div>

          <div class="col-lg-12">
              <section class="panel">
                  <header class="panel-heading">
                      工时成本计算步骤完成记录
                  </header>
                  <div class="panel-body">
                      <!--历史记录-->
                      <div id="clHistryContainer" class="dlshouwen-grid-container"></div>
                      <div id="clHistryToolContainer" class="dlshouwen-grid-toolbar-container"></div>
                  </div>
              </section>
          </div>
      </div>
    </section>
  </section>
  <!--main content end-->
</section>
<script type="text/javascript" src="assets/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="js/autocomplete/jquery.autocomplete.js"></script>
<!-- 当前页面js文件引入 -->
<script type="text/javascript">
    $("#beginTime").datepicker({
        format: 'yyyy-mm-dd'
    });
    $("#endTime").datepicker({
        format: 'yyyy-mm-dd'
    });
    $("#isShowBg").hide();

    $("#begindiv").hide();
    $("#enddiv").hide();

    function getServerDate(){
        //IE不兼容
        return new Date($.ajax({type:'HEAD',async: false}).getResponseHeader("Date"));
    }

    function getCostType(type) {
        if (type=="N"){
            //获取上个月 日期
            var date = getServerDate();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var day = date.getDate();
            if (month==1){
                $("#beginTime").val((year-1)+"-"+"01-01");
            }else{
                var m = month-1;
                if (m<10){
                    m = "0"+m;
                }
                $("#beginTime").val(year+"-"+m+"-01");
            }
            if (month<10){
                month = "0"+month;
            }
            if (day<10){
                day = "0"+day;
            }
            $("#endTime").val(year+"-"+month+"-"+day);

            $("#beginTime").attr("disabled",false);
            $("#endTime").attr("disabled",false);
        }else{
            $("#beginTime").val("");
            $("#endTime").val("");
            $("#beginTime").attr("disabled",true);
            $("#endTime").attr("disabled",true);
        }
    }

    // getCostType("N");
  function findCUser(CertusFormAjax, $scope) {
      var y1 = 0;
      var m1 = 0;
      var isYfBtn = true;
      var isKfBtn = true;
      this.canTj = function () {
          CertusFormAjax.ajax('findMaxTjTime',{},function (result) {
              y1 = result.data.year;
              m1 = result.data.month;

              //用服人员
              CertusFormAjax.ajax('findPreMonthStep',{"year":y1,"month":m1},function (response) {
                  if (!response.data){
                      $(".tjyf").attr("disabled",true);
                      isYfBtn = false;
                  }else{
                      $(".tjyf").attr("disabled",false);
                  }
              });

              //开发人员
              CertusFormAjax.ajax('findPreMonthStep2',{"year":y1,"month":m1},function (response) {
                  if (!response.data){
                      $(".tjkf").attr("disabled",true);
                      isKfBtn = false;
                  }else{
                      $(".tjkf").attr("disabled",false);
                  }
              });
          });
      };
      canTj();
      this.search = function (code,beginTime,endTime) {
          $("#cuserContainer").empty();
          $("#cuserToolContainer").empty();
          var wpColumns = "";
          if(code=="N"){
              //工作安排
              wpColumns = [{
                  id: 'userName',
                  title: '姓名',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'userId',
                  title: '工号',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'company',
                  title: '归属公司',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'dep3_name',
                  title: '上市部门',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'dep1_name',
                  title: '归属部门',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'dep3_before_name',
                  title: '上次上市部门',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'enrollTime',
                  title: '入职时间',
                  type: 'string',
                  columnClass: 'text-center',
                  width: 110
              }, {
                  id: 'positonName',
                  title: '岗位',
                  type: 'string',
                  columnClass: 'text-center',
                  width: 110
              }, {
                  id: 'costType',
                  title: '成本种类',
                  type: 'string',
                  columnClass: 'text-center',
                  resolution: function (value, record) {
                      var content = '';
                      if (value=="KF-001") {
                          content = '开发成本';
                      }else if (value=="YF-001"){
                          content = '用服成本';
                      }else if (value=="OT-001"){
                          content = '销管成本';
                      }else if (value==""||value=="无"){
                          content = '未分配';
                      }else {
                          content = '其他';
                      }
                      return content;
                  }
              }, {
                  id: 'createUser',
                  title: '设定人员',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType:'lg|md|sm|xs'
              }, {
                  id: 'proName',
                  title: '归属项目',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'moduleName',
                  title: '归属模块',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'createTime',
                  title: '设定时间',
                  type: 'date',
                  format: 'yyyy-MM-dd',
                  otype: 'time_stamp_ms',
                  columnClass: 'text-center',
                  width: 180
              },{
                  id: 'comments',
                  title: '注释',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'operation',
                  title: '操作',
                  width: 130,
                  type: 'string',
                  columnClass: 'text-center',
                  resolution: function (value, record) {
                      var isNuser = "1";
                      var content ="";
                      var enroll = record.enrollTime+","+record.comments;

                      //为用服人员的时候只能设置为销管
                      if (record.costType=="YF-001"){
                          //设置销售管理人员
                          //是否已经提交这次的用服人员 true未提交
                          if (isYfBtn){
                              content+=" ";
                              content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  释放</button>';
                          }else{
                              content+=" ";
                              content+='无';
                          }

                      }
                      if (record.costType=="KF-001"){
                          //如果为开发人员只能设置为销管
                          //设置销售管理人员
                          if (isKfBtn){
                              content+=" ";
                              content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  释放</button>';
                          }else{
                              content+=" ";
                              content+='无';
                          }

                      }
                      if(record.costType=="OT-001"){
                          // //设置销售管理人员
                          // if (isYfBtn){
                          //     content+=" ";
                          //     content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'YF-001\',\''+record.enrollTime+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  用服</button>';
                          // }
                          // //设置销售管理人员
                          // if (isKfBtn){
                          //     content+=" ";
                          //     content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'KF-001\',\''+record.enrollTime+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  开发</button>';
                          // }
                          content+=" ";
                          content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  释放</button>';
                      }

                      if (record.costType==""||record.costType=="无"){
                          isNuser="0";
                          //未分配人员
                          if (isYfBtn){
                              content+=" ";
                              content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'YF-001\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  用服</button>';
                          }
                          if (isKfBtn){
                              content+=" ";
                              // content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'OT-001\',\''+record.enrollTime+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  销管</button>';
                              content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'KF-001\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  开发</button>';
                          }
                          if (!isYfBtn&&!isKfBtn){
                              content+=" ";
                              // content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'OT-001\',\''+record.enrollTime+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  销管</button>';
                              content+='无';
                          }
                      }

                      return content;
                  }
              }];
          }else if (code=="KF-001"){
              //工作安排
              wpColumns = [{
                  id: 'userName',
                  title: '姓名',
                  type: 'string',
                  width:70,
                  columnClass: 'text-center'
              }, {
                  id: 'userId',
                  title: '工号',
                  type: 'string',
                  width:70,
                  columnClass: 'text-center'
              }, {
                  id: 'company',
                  title: '归属公司',
                  type: 'string',
                  width:90,
                  columnClass: 'text-center'
              }, {
                  id: 'dep3_name',
                  title: '上市部门',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'dep1_name',
                  title: '归属部门',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'dep3_before_name',
                  title: '上次上市部门',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'costType',
                  title: '成本',
                  type: 'string',
                  width:70,
                  columnClass: 'text-center',
                  resolution: function (value, record) {
                      var content = '';
                      if (value=="KF-001") {
                          content = '开发成本';
                      }else if (value=="YF-001"){
                          content = '用服成本';
                      }else if (value=="OT-001"){
                          content = '销管成本';
                      }else if (value==""||value=="无"){
                          content = '未分配员工';
                      }else {
                          content = '其他';
                      }
                      return content;
                  }
              }, {
                  id: 'beforCostType',
                  title: '上次成本',
                  type: 'string',
                  width:70,
                  columnClass: 'text-center',
                  resolution: function (value, record) {
                      var content = '';
                      if (value!=record.costType){
                          if (value=="KF-001") {
                              content = '<span style="color: #be1616">开发</span>';
                          }else if (value=="YF-001"){
                              content = '<span style="color: #be1616">用服</span>';
                          }else if (value=="OT-001"){
                              content = '<span style="color: #be1616">销管</span>';
                          }else if (value=="undefined"){
                              content = '<span style="color: #be1616">未分配</span>';
                          }else {
                              content = '<span style="color: #be1616">其他</span>';
                          }
                      }else{
                          if (value=="KF-001") {
                              content = '开发成本';
                          }else if (value=="YF-001"){
                              content = '用服成本';
                          }else if (value=="OT-001"){
                              content = '销管成本';
                          }else if (value==""||value=="无"){
                              content = '未分配';
                          }else {
                              content = '其他';
                          }
                      }
                      return content;
                  }
              }, {
                  id: 'createUser',
                  title: '设定人员',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'proName',
                  title: '归属项目',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'moduleName',
                  title: '归属模块',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'createTime',
                  title: '设定时间',
                  type: 'date',
                  format: 'yyyy-MM-dd',
                  otype: 'time_stamp_ms',
                  width:100,
                  columnClass: 'text-center'
              },{
                  id: 'comments',
                  title: '注释',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'operation',
                  title: '操作',
                  width: 80,
                  type: 'string',
                  columnClass: 'text-center',
                  resolution: function (value, record) {
                      var isNuser = "1";
                      var content ="";
                      var enroll = record.enrollTime+","+record.comments;
                      //为用服人员的时候只能设置为销管
                      if (record.costType=="YF-001"){
                          //设置销售管理人员
                          //是否已经提交这次的用服人员 true未提交
                          if (isYfBtn){
                              content+=" ";
                              content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  释放</button>';
                          }else{
                              content+=" ";
                              content+='无';
                          }

                      }
                      if (record.costType=="KF-001"){
                          //如果为开发人员只能设置为销管
                          //设置销售管理人员
                          if (isKfBtn){
                              content+=" ";
                              content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  释放</button>';
                          }else{
                              content+=" ";
                              content+='无';
                          }

                      }
                      if(record.costType=="OT-001"){
                          // //设置销售管理人员
                          // if (isYfBtn){
                          //     content+=" ";
                          //     content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'YF-001\',\''+record.enrollTime+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  用服</button>';
                          // }
                          // //设置销售管理人员
                          // if (isKfBtn){
                          //     content+=" ";
                          //     content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'KF-001\',\''+record.enrollTime+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  开发</button>';
                          // }
                          content+=" ";
                          content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  释放</button>';
                      }

                      if (record.costType==""||record.costType=="无"){
                          isNuser="0";
                          //未分配人员
                          if (isYfBtn){
                              content+=" ";
                              content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'YF-001\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  用服</button>';
                          }
                          if (isKfBtn){
                              content+=" ";
                              // content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'OT-001\',\''+record.enrollTime+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  销管</button>';
                              content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'KF-001\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  开发</button>';
                          }
                          if (!isYfBtn&&!isKfBtn){
                              content+=" ";
                              // content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'OT-001\',\''+record.enrollTime+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  销管</button>';
                              content+='无';
                          }
                      }

                      return content;
                  }
              }];
          }else{
              //工作安排
              wpColumns = [{
                  id: 'userName',
                  title: '姓名',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'userId',
                  title: '工号',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'company',
                  title: '归属公司',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'dep3_name',
                  title: '上市部门',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'dep1_name',
                  title: '归属部门',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'dep3_before_name',
                  title: '上次上市部门',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'costType',
                  title: '成本种类',
                  type: 'string',
                  columnClass: 'text-center',
                  resolution: function (value, record) {
                      var content = '';
                      if (value=="KF-001") {
                          content = '开发成本';
                      }else if (value=="YF-001"){
                          content = '用服成本';
                      }else if (value=="OT-001"){
                          content = '销管成本';
                      }else if (value==""||value=="无"){
                          content = '未分配';
                      }else {
                          content = '其他';
                      }
                      return content;
                  }
              }, {
                  id: 'beforCostType',
                  title: '上次成本',
                  type: 'string',
                  width:70,
                  columnClass: 'text-center',
                  resolution: function (value, record) {
                      var content = '';
                      if (value!=record.costType){
                          if (value=="KF-001") {
                              content = '<span style="color: #be1616">开发</span>';
                          }else if (value=="YF-001"){
                              content = '<span style="color: #be1616">用服</span>';
                          }else if (value=="OT-001"){
                              content = '<span style="color: #be1616">销管</span>';
                          }else if (value=="undefined"){
                              content = '<span style="color: #be1616">未分配</span>';
                          }else {
                              content = '<span style="color: #be1616">其他</span>';
                          }
                      }else{
                          if (value=="KF-001") {
                              content = '开发成本';
                          }else if (value=="YF-001"){
                              content = '用服成本';
                          }else if (value=="OT-001"){
                              content = '销管成本';
                          }else if (value==""||value=="无"){
                              content = '未分配';
                          }else {
                              content = '其他';
                          }
                      }
                      return content;
                  }
              },{
                  id: 'createUser',
                  title: '设定人员',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'proName',
                  title: '归属项目',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'moduleName',
                  title: '归属模块',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'createTime',
                  title: '设定时间',
                  type: 'date',
                  format: 'yyyy-MM-dd',
                  otype: 'time_stamp_ms',
                  columnClass: 'text-center',
                  width: 180
              },{
                  id: 'comments',
                  title: '注释',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'operation',
                  title: '操作',
                  width: 130,
                  type: 'string',
                  columnClass: 'text-center',
                  resolution: function (value, record) {
                      var isNuser = "1";
                      var content ="";
                      var enroll = record.enrollTime+","+record.comments;
                      //为用服人员的时候只能设置为销管
                      if (record.costType=="YF-001"){
                          //设置销售管理人员
                          //是否已经提交这次的用服人员 true未提交
                          if (isYfBtn){
                              content+=" ";
                              content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  释放</button>';
                          }else{
                              content+=" ";
                              content+='无';
                          }

                      }
                      if (record.costType=="KF-001"){
                          //如果为开发人员只能设置为销管
                          //设置销售管理人员
                          if (isKfBtn){
                              content+=" ";
                              content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  释放</button>';
                          }else{
                              content+=" ";
                              content+='无';
                          }

                      }
                      if(record.costType=="OT-001"){
                          // //设置销售管理人员
                          // if (isYfBtn){
                          //     content+=" ";
                          //     content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'YF-001\',\''+record.enrollTime+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  用服</button>';
                          // }
                          // //设置销售管理人员
                          // if (isKfBtn){
                          //     content+=" ";
                          //     content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'KF-001\',\''+record.enrollTime+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  开发</button>';
                          // }
                          content+=" ";
                          content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  释放</button>';
                      }

                      if (record.costType==""||record.costType=="无"){
                          isNuser="0";
                          //未分配人员
                          if (isYfBtn){
                              content+=" ";
                              content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'YF-001\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  用服</button>';
                          }
                          if (isKfBtn){
                              content+=" ";
                              // content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'OT-001\',\''+record.enrollTime+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  销管</button>';
                              content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'KF-001\',\''+enroll+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  开发</button>';
                          }
                          if (!isYfBtn&&!isKfBtn){
                              content+=" ";
                              // content += '<button class="btn btn-xs btn-info" onclick="editWp(' + record.id+ ',\'OT-001\',\''+record.enrollTime+'\',\''+isNuser+'\');"><i class="fa fa-edit"></i>  销管</button>';
                              content+='无';
                          }
                      }

                      return content;
                  }
              }];
          }

          var userIdN = $("#userIdN").val();
          var companyCodeN = $("#companyCodeN").val();
          var deptCodeN = $("#deptCodeN").val();
          CertusFormAjax.ajax('findCareeUsers', {
              "code": code,
              "beginTime":beginTime,
              "endTime":endTime,
              "userId":userIdN,
              "companyCode":companyCodeN,
              "deptCode":deptCodeN
          }, function (response) {
              var makingOption = {
                  lang: 'zh-cn',
                  ajaxLoad: false,
                  extraWidth: 20,
                  // loadURL:'url',
                  exportFileName: '员工成本',
                  datas: response.data,
                  columns: wpColumns,
                  gridContainer: 'cuserContainer',
                  toolbarContainer: 'cuserToolContainer',
                  tools: '',
                  pageSize: 10,
                  pageSizeLimit: [10, 15, 20,100]
              };
              var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
              makingGrid.load();
          });
      };

      setTimeout(function () {
          search("N","","");
      },50);

      lzColumns = [{
          id: 'userName',
          title: '姓名',
          type: 'string',
          columnClass: 'text-center'
      }, {
          id: 'userId',
          title: '工号',
          type: 'string',
          columnClass: 'text-center'
      }, {
          id: 'company',
          title: '归属公司',
          type: 'string',
          columnClass: 'text-center'
      }, {
          id: 'dep3_name',
          title: '上市部门',
          type: 'string',
          columnClass: 'text-center'
      }, {
          id: 'dep1_name',
          title: '归属部门',
          type: 'string',
          columnClass: 'text-center',
          hideType: 'lg|md|sm|xs'
      }, {
          id: 'feeEndDate',
          title: '费用结算日期',
          type: 'string',
          columnClass: 'text-center',
          width: 110
      }, {
          id: 'costType',
          title: '成本种类',
          type: 'string',
          columnClass: 'text-center',
          resolution: function (value, record) {
              var content = '';
              if (value=="KF-001") {
                  content = '开发成本';
              }else if (value=="YF-001"){
                  content = '用服成本';
              }else if (value=="OT-001"){
                  content = '销管成本';
              }else if (value==""){
                  content = '未分配';
              }else {
                  content = '其他';
              }
              return content;
          }
      }, {
          id: 'createUser',
          title: '设定人员',
          type: 'string',
          columnClass: 'text-center'
      }, {
          id: 'createTime',
          title: '设定时间',
          type: 'date',
          format: 'yyyy-MM-dd hh:mm:ss',
          otype: 'time_stamp_ms',
          columnClass: 'text-center',
          width: 180
      }, {
          id: 'proName',
          title: '归属项目',
          type: 'string',
          columnClass: 'text-center',
          hideType: 'lg|md|sm|xs'
      }, {
          id: 'moduleName',
          title: '归属模块',
          type: 'string',
          columnClass: 'text-center',
          hideType: 'lg|md|sm|xs'
      }];
      CertusFormAjax.ajax('findNpostUsers', {
      }, function (response) {
          var makingOption = {
              lang: 'zh-cn',
              ajaxLoad: false,
              extraWidth: 20,
              // loadURL:'url',
              exportFileName: '员工成本',
              datas: response.data,
              columns: lzColumns,
              gridContainer: 'lzContainer',
              toolbarContainer: 'lzHistryToolContainer',
              tools: '',
              pageSize: 10,
              pageSizeLimit: [10, 15, 20]
          };
          var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
          makingGrid.load();
      });

      rzColumns = [{
          id: 'userName',
          title: '姓名',
          type: 'string',
          columnClass: 'text-center'
      }, {
          id: 'userId',
          title: '工号',
          type: 'string',
          columnClass: 'text-center'
      }, {
          id: 'readyToWork',
          title: '入职时间',
          type: 'string',
          columnClass: 'text-center'
      }, {
          id: 'positonName',
          title: '职位',
          type: 'string',
          columnClass: 'text-center'
      }, {
          id: 'dep2_name',
          title: '部门',
          type: 'string',
          columnClass: 'text-center'
      }, {
          id: 'company',
          title: '公司',
          type: 'string',
          columnClass: 'text-center'
      }];

      CertusFormAjax.ajax('findOpostUser', {
      }, function (response) {
          var makingOption = {
              lang: 'zh-cn',
              ajaxLoad: false,
              extraWidth: 20,
              // loadURL:'url',
              exportFileName: '待入职人员列表',
              datas: response.data,
              columns: rzColumns,
              gridContainer: 'rzContainer',
              toolbarContainer: 'rzHistryToolContainer',
              tools: '',
              pageSize: 10,
              pageSizeLimit: [10, 15, 20]
          };
          var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
          makingGrid.load();
      });

      this.hisSearch = function () {
          //历史记录
          var hisColumns = [{
              id: 'userName',
              title: '姓名',
              type: 'string',
              columnClass: 'text-center'
          }, {
              id: 'userId',
              title: '工号',
              type: 'string',
              columnClass: 'text-center'
          }, {
              id: 'costType',
              title: '成本种类',
              type: 'string',
              columnClass: 'text-center',
              resolution: function (value, record) {
                  var content = '';
                  if (value=="KF-001") {
                      content = '开发';
                  }else if (value=="YF-001"){
                      content = '用服成本';
                  }else if (value=="OT-001"){
                      content = '销管';
                  }else if (value==""){
                      content = '未分配';
                  }else {
                      content = '其他';
                  }
                  return content;
              }
          }, {
              id: 'beforCostType',
              title: '上次成本',
              type: 'string',
              columnClass: 'text-center',
              resolution: function (value, record) {
                  var content = '';
                  if (value!=record.costType){
                      if (value=="KF-001") {
                          content = '<span style="color: #be1616">开发</span>';
                      }else if (value=="YF-001"){
                          content = '<span style="color: #be1616">用服</span>';
                      }else if (value=="OT-001"){
                          content = '<span style="color: #be1616">销管</span>';
                      }else if (value==""){
                          content = '<span style="color: #be1616">未分配</span>';
                      }else {
                          content = '<span style="color: #be1616">其他</span>';
                      }
                  }else{
                      if (value=="KF-001") {
                          content = '开发';
                      }else if (value=="YF-001"){
                          content = '用服';
                      }else if (value=="OT-001"){
                          content = '销管';
                      }else if (value==""){
                          content = '未分配';
                      }else {
                          content = '其他';
                      }
                  }
                  return content;
              }
          }, {
              id: 'createUser',
              title: '上次设定人员',
              type: 'string',
              columnClass: 'text-center'
          }, {
              id: 'createTime',
              title: '上次设定时间',
              type: 'date',
              format: 'yyyy-MM-dd hh:mm:ss',
              otype: 'time_stamp_ms',
              columnClass: 'text-center',
              width: 180
          }, {
              id: 'proName',
              title: '归属项目',
              type: 'string',
              columnClass: 'text-center',
              hideType: 'lg|md|sm|xs'
          }, {
              id: 'moduleName',
              title: '归属模块',
              type: 'string',
              columnClass: 'text-center',
              hideType: 'lg|md|sm|xs'
          }, {
              id: 'comments',
              title: '注释',
              type: 'string',
              columnClass: 'text-center'
          }];

          $("#cuserHistryContainer").empty();
          $("#cuserHistryToolContainer").empty();
          CertusFormAjax.ajax('findCareeUserHirst', {
          }, function (response) {
              var makingOption = {
                  lang: 'zh-cn',
                  ajaxLoad: false,
                  extraWidth: 20,
                  // loadURL:'url',
                  exportFileName: '员工成本',
                  datas: response.data,
                  columns: hisColumns,
                  gridContainer: 'cuserHistryContainer',
                  toolbarContainer: 'cuserHistryToolContainer',
                  tools: '',
                  pageSize: 10,
                  pageSizeLimit: [10, 15, 20]
              };
              var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
              makingGrid.load();
          });
      };
      hisSearch();

      this.searchBz = function () {
          //成本列表
          var clColumns = [{
              id: 'ltime',
              title: '月份',
              type: 'string',
              columnClass: 'text-center'
          },{
              id: 'step1UserName',
              title: '用服确认人',
              type: 'string',
              columnClass: 'text-center',
              width: 60
          }, {
              id: 'step1ConfirmTime',
              title: '用服确认时间',
              type: 'string',
              columnClass: 'text-center',
              width: 100
          }, {
              id: 'step1comment',
              title: '用服说明',
              type: 'string',
              columnClass: 'text-center'
          }, {
              id: 'step2UserName',
              title: '开发确认人',
              type: 'string',
              columnClass: 'text-center',
              width: 60
          }, {
              id: 'step2ConfirmTime',
              title: '开发确认时间',
              type: 'string',
              columnClass: 'text-center',
              width: 100
          }, {
              id: 'step2comment',
              title: '开发说明',
              type: 'string',
              columnClass: 'text-center'
          }, {
              id: 'step3UserName',
              title: '成本确认人',
              type: 'string',
              columnClass: 'text-center',
              width: 60
          }, {
              id: 'step3comment',
              title: '成本说明',
              type: 'string',
              columnClass: 'text-center'
          }, {
              id: 'step3ConfirmTime',
              title: '成本确认时间',
              type: 'string',
              columnClass: 'text-center',
              width: 100
          }, {
              id: 'releaseTime',
              title: '成本计算时间',
              type: 'string',
              columnClass: 'text-center',
              width: 100
          }];

          $("#clHistryContainer").empty();
          $("#clHistryToolContainer").empty();
          CertusFormAjax.ajax('findCmcList', {
          }, function (response) {
              var makingOption = {
                  lang: 'zh-cn',
                  ajaxLoad: false,
                  extraWidth: 20,
                  // loadURL:'url',
                  exportFileName: '员工成本',
                  datas: response.data,
                  columns: clColumns,
                  gridContainer: 'clHistryContainer',
                  toolbarContainer: 'clHistryToolContainer',
                  tools: '',
                  pageSize: 10,
                  pageSizeLimit: [10, 15, 20]
              };
              var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
              makingGrid.load();
          });
      };
      searchBz();

      $(".psearch").click(function () {
          var costType = $("#costType").val();
          var userIdN = $("#userIdN").val();
          var companyCodeN = $("#companyCodeN").val();
          var deptCodeN = $("#deptCodeN").val();
          // var beginTime = $("#beginTime").val();
          // var endTime = $("#endTime").val();
          search(costType,"","");
      });

      this.editWp = function (id,costType,enrollTime,isNuser) {
          cleanOkrs();
          CertusFormAjax.ajax('findGrInfos',{"id":id},function (response) {
              var data = response.data;
              $scope.userName = data.userName+"("+data.userId+")";
              $scope.company = data.company;
              $scope.positionName = data.positionName;
          });
          // CertusFormAjax.ajax('findSdepts',{},function (response) {
          //     $scope.sdeptList = response.data;
          // });
          $("#isShowBg").show();
          if (costType=="KF-001"){
              //研发人员需要选中项目和模块
              $(".isYf").show();
          }else{
              $(".isYf").hide();
          }
          scrollToLocation();
          $scope.costType = costType;
          $scope.id = id;
          var eltime = enrollTime.split(",")[0];
          var comment = enrollTime.split(",")[1];

          if (comment=="undefined"){
              comment="";
          }
          if (isNuser=="0"){
              $("#comment").attr("placeholder","入职时间："+eltime+"(120字以内)");
              $("#comment").val(comment);
          }else{
              $("#comment").val(comment);
          }
          $scope.enrollTime = enrollTime;
      };
      $(".tjyf").click(function () {
          $scope.cmt = 1;
          $("#stepCmt").show();
          $("#isShowBg").hide();
      });
      $(".tjkf").click(function () {
          $scope.cmt = 2;
          $("#stepCmt").show();
          $("#isShowBg").hide();
      });

      this.addCmt = function () {
          if ($scope.cmt==1){
              layer.confirm('是否提交'+y1+'年'+m1+'月用服人员？', {
                  title: '提示信息',
                  btn: ['是', '否'] //按钮
              }, function () {
                  // 开启
                  var index = layer.load(1);
                  CertusFormAjax.ajax('addMonthStep1',{"year":y1,"month":m1,"comment":$("#stepComment").val()},function () {
                      canTj();
                      setTimeout(function () {
                          search($("#costType").val(),"","");
                      },50);
                      $("#stepCmt").hide();
                      //关闭
                      layer.close(index);
                      layer.msg("提交成功！");
                  });
              });
          }else{
              layer.confirm('是否提交'+y1+'年'+m1+'开发人员？', {
                  title: '提示信息',
                  btn: ['是', '否'] //按钮
              }, function () {
                  // 开启
                  var index = layer.load(1);
                  CertusFormAjax.ajax('addMonthStepN',{"year":y1,"month":m1,"comment":$("#stepComment").val()},function () {
                      canTj();
                      setTimeout(function () {
                          search($("#costType").val(),"","");
                      },50);
                      $("#stepCmt").hide();
                      //关闭
                      layer.close(index);
                      layer.msg("提交成功！");
                  });
              });
          }
      };

      CertusFormAjax.ajax("findSpUserList",{},function (response) {
          var nhlTeams = [];
          var data = response.data;
          for (var i=0;i<data.length;i++){
              var arr={};
              arr.name=data[i].userName+"["+data[i].positonName+"]";
              arr.id = data[i].userId;
              nhlTeams.push(arr);
          }
          //自动补全
          var nhl = $.map(nhlTeams, function (obj) {
              return {
                  value: obj.name,
                  data: { category: obj.id }
              };
          });
          //产品经理
          $('#useName').devbridgeAutocomplete({
              lookup: nhl,
              minChars: 1,
              onSelect: function (suggestion) {
                  $("#userId").val(suggestion.data.category);
              },
              showNoSuggestionNotice: true,
              noSuggestionNotice: 'Sorry, no matching results'
          });

          $('#useNameN').devbridgeAutocomplete({
              lookup: nhl,
              minChars: 1,
              onSelect: function (suggestion) {
                  $("#userIdN").val(suggestion.data.category);
              },
              showNoSuggestionNotice: true,
              noSuggestionNotice: 'Sorry, no matching results'
          });
      });

      CertusFormAjax.ajax('deptedList',{},function (response) {
          var data = response.data;
          $scope.depts = JSON.parse(data);
      });

      this.searchHist = function () {
          var hymColumns= "";
          var lsCostType = $("#lsCostType").val();
          if (lsCostType=="KF-001"){
              //工作安排
              hymColumns = [{
                  id: 'userName',
                  title: '姓名',
                  type: 'string',
                  width:70,
                  columnClass: 'text-center'
              }, {
                  id: 'userId',
                  title: '工号',
                  type: 'string',
                  width:70,
                  columnClass: 'text-center'
              }, {
                  id: 'company',
                  title: '归属公司',
                  type: 'string',
                  width:90,
                  columnClass: 'text-center'
              }, {
                  id: 'dep3_name',
                  title: '上市部门',
                  type: 'string',
                  width:100,
                  columnClass: 'text-center'
              }, {
                  id: 'dep2_name',
                  title: '归属部门',
                  type: 'string',
                  width:100,
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'costType',
                  title: '成本',
                  type: 'string',
                  width:70,
                  columnClass: 'text-center',
                  resolution: function (value, record) {
                      var content = '';
                      if (value=="KF-001") {
                          content = '开发';
                      }else if (value=="YF-001"){
                          content = '用服';
                      }else if (value=="OT-001"){
                          content = '销管';
                      }else if (value==""){
                          content = '未分配';
                      }else {
                          content = '其他';
                      }
                      return content;
                  }
              }, {
                  id: 'beforCostType',
                  title: '上次成本',
                  type: 'string',
                  width:70,
                  columnClass: 'text-center',
                  resolution: function (value, record) {
                      var content = '';
                      if (value!=record.costType){
                          if (value=="KF-001") {
                              content = '<span style="color: #be1616">开发</span>';
                          }else if (value=="YF-001"){
                              content = '<span style="color: #be1616">用服</span>';
                          }else if (value=="OT-001"){
                              content = '<span style="color: #be1616">销管</span>';
                          }else if (value=="undefined"){
                              content = '<span style="color: #be1616">未分配</span>';
                          }else {
                              content = '<span style="color: #be1616">其他</span>';
                          }
                      }else{
                          if (value=="KF-001") {
                              content = '开发';
                          }else if (value=="YF-001"){
                              content = '用服';
                          }else if (value=="OT-001"){
                              content = '销管';
                          }else if (value==""){
                              content = '未分配';
                          }else {
                              content = '其他';
                          }
                      }
                      return content;
                  }
              }, {
                  id: 'createUser',
                  title: '设定人员',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'proName',
                  title: '归属项目',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'moduleName',
                  title: '归属模块',
                  type: 'string',
                  columnClass: 'text-center'
              },{
                  id: 'comments',
                  title: '注释',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'createTime',
                  title: '设定时间',
                  type: 'date',
                  format: 'yyyy-MM-dd',
                  otype: 'time_stamp_ms',
                  width:100,
                  columnClass: 'text-center'
              }];
          }else{
              //工作安排
              hymColumns = [{
                  id: 'userName',
                  title: '姓名',
                  type: 'string',
                  columnClass: 'text-center'
              },{
                  id: 'yd',
                  title: '日期',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'userId',
                  title: '工号',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'company',
                  title: '归属公司',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'dep3_name',
                  title: '上市部门',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'dep2_name',
                  title: '归属部门',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'costType',
                  title: '成本种类',
                  type: 'string',
                  columnClass: 'text-center',
                  resolution: function (value, record) {
                      var content = '';
                      if (value=="KF-001") {
                          content = '开发成本';
                      }else if (value=="YF-001"){
                          content = '用服成本';
                      }else if (value=="OT-001"){
                          content = '销管成本';
                      }else if (value==""){
                          content = '未分配';
                      }else {
                          content = '其他';
                      }
                      return content;
                  }
              }, {
                  id: 'createUser',
                  title: '设定人员',
                  type: 'string',
                  columnClass: 'text-center'
              }, {
                  id: 'createTime',
                  title: '设定时间',
                  type: 'date',
                  format: 'yyyy-MM-dd hh:mm:ss',
                  otype: 'time_stamp_ms',
                  columnClass: 'text-center',
                  width: 180,
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'feeEndDate',
                  title: '离职时间',
                  type: 'string',
                  columnClass: 'text-center',
                  width: 110,
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'proName',
                  title: '归属项目',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'moduleName',
                  title: '归属模块',
                  type: 'string',
                  columnClass: 'text-center',
                  hideType: 'lg|md|sm|xs'
              }, {
                  id: 'comments',
                  title: '注释',
                  type: 'string',
                  columnClass: 'text-center'
              }];
          }

          var pyear = $("#pyear").val();
          var pmonth = $("#pmonth").val();
          var userId = $("#userId").val();
          var deptCode = $("#deptCode").val();

          $("#aContainer").empty();
          $("#aToolContainer").empty();
          CertusFormAjax.ajax('findCareeUserHym', {
              "year": pyear,
              "month":pmonth,
              "userId":userId,
              "deptCode":deptCode,
              "costType":lsCostType,
              "company":$("#companyCode").val(),
              "proName":"",
              "moduleId":0
          }, function (response) {
              var makingOption = {
                  lang: 'zh-cn',
                  ajaxLoad: false,
                  extraWidth: 20,
                  // loadURL:'url',
                  exportFileName: '员工成本',
                  datas: response.data,
                  columns: hymColumns,
                  gridContainer: 'aContainer',
                  toolbarContainer: 'aToolContainer',
                  tools: '',
                  pageSize: 10,
                  pageSizeLimit: [10, 15, 20,100]
              };
              var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
              makingGrid.load();
          });
      };
      searchHist();
      $(".downLoad").click(function () {
          var lsCostType = $("#lsCostType").val();
          var pyear = $("#pyear").val();
          var pmonth = $("#pmonth").val();
          if(pyear==0||pmonth==0){
              layer.msg("请选择年份和月份");
              return;
          }
          var userId = $("#userId").val();
          var deptCode = $("#deptCode").val();

          CertusFormAjax.download("downLoadCareeUserHis", "year=" + pyear + "&month="
              + pmonth + "&userId=" + userId + "&deptCode=" + deptCode
              + "&costType=" + lsCostType + "&company=" + $("#companyCode").val()
              +"&proName="+" "+"&moduleId=0");
      });

      $(".searchhis").click(function () {
          searchHist();
      });

      CertusFormAjax.ajax("findSeProList1",{},function(response){
          var nhlTeams = [];
          var data = response.data;
          for (var i=0;i<data.length;i++){
              var arr={};
              arr.name=data[i].proName;
              arr.id = data[i].id;
              nhlTeams.push(arr);
          }
          //自动补全
          var nhl = $.map(nhlTeams, function (obj) {
              return {
                  value: obj.name,
                  data: { category: obj.id }
              };
          });
          // Initialize autocomplete with local lookup:
          $('#proName').devbridgeAutocomplete({
              lookup: nhl,
              minChars: 1,
              onSelect: function (suggestion) {
                  $("#proId").val(suggestion.data.category);
                  getModule(suggestion.data.category);
              },
              showNoSuggestionNotice: true,
              noSuggestionNotice: 'Sorry, no matching results'
          });

      });

      this.getModule = function (proId) {
          CertusFormAjax.ajax('findModuleByProId',{"proId":proId},function (response) {
              $scope.moduleList = response.data;
          });
      };

      // CertusFormAjax.ajax('findRoleByPtype',{},function (response) {
      //     $scope.roleList = response.data;
      // });

      this.addOkrs = function () {
         var arr = {};
         arr.costType = $scope.costType;
         arr.id = $scope.id;
         if ($scope.costType=="KF-001"){
             //用服人员
             var proName = $("#proName").val();
             var proId = $("#proId").val();
             var moduleId = $("#moduleId").val();
             var moduleName = $("#moduleId").find("option:selected").text().trim();
             var roleId = $("#roleId").val();
             var roleName = $("#roleId").find("option:selected").text().trim();
             if (proId==""){
                 layer.msg("请选择项目");
                 return;
             }
             if(moduleId==0){
                 layer.msg("请选择模块");
                 return;
             }
             if(roleId==""){
                 layer.msg("请选择角色");
                 return;
             }
             arr.proName = proName;
             arr.proId = proId;
             arr.moduleId = moduleId;
             arr.moduleName = moduleName;
             arr.roleId = roleId;
             arr.roleName = roleName;
         }
         var comments = $("#comment").val();
         var sdeptCode = $("#sdeptCode").val();
         var sdeptName = $("#sdeptCode option:selected").text().trim();
         arr.comments = comments;
         arr.sdeptCode = sdeptCode;
         arr.sdeptName = sdeptName;
          layer.confirm('是否更换人员类型？', {
              title: '提示信息',
              btn: ['是', '否'] //按钮
          }, function () {
              CertusFormAjax.ajax('editCareeUser',{"param":JSON.stringify(arr)},function (response) {
                  var rd = response.data.split(",");
                  if (rd[0]==0){
                      $(".psearch").click();
                      searchBz();
                      hisSearch();
                  }
                  layer.msg(rd[1]);
                  cleanOkrs();
              });
          });
      };
  }

  function cleanOkrs() {
      $("#proName").val("");
      $("#comment").val("");
      $("#proId").val("");
      $("#moduleId").val(0);
      $("#roleId").val("");
      $("#isShowBg").hide();
  }

    function scrollToLocation() {
        $("#comment").focus();
        var mainContainer = $('#isShowBg'),
            scrollToContainer = mainContainer.find('.bg');
        mainContainer.animate({
            scrollTop: scrollToContainer.offset().top - mainContainer.offset().top + mainContainer.scrollTop()
        }, 1000);//2秒滑动到指定位置
    }

    function cleaUser() {
        $("#userIdN").val("")
    }

    function cleaUser2() {
        $("#userId").val("")
    }

    function cleanCmt() {
        $("#stepCmt").hide();
    }
</script>